import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
public class longest_lines {
    public static void main (String[] args) throws IOException{
        if (args.length<1) throw new RuntimeException ("not enough arguments");
        if (args.length>1) throw new RuntimeException ("too many arguments");
        BufferedReader reader = new BufferedReader (new FileReader (new File (args[0])));
        String line;
        boolean firstLine = true;
        int N = 0;
        HashMap <String,Integer> map = new HashMap <String,Integer>();
        while ((line = reader.readLine()) != null ){
            if (firstLine){
                N = Integer.parseInt(line); 
                firstLine = false;
            }
            else {
              map.put(line, line.length());  
            }
        }
        //after you load all the lines into the hashmap start processing
        Object[] lines = map.keySet().toArray();
        Arrays.sort(lines);
        Object[] l =  map.entrySet().toArray();
        int linesPrinted = 0;
        for (int i = lines.length-1;i>0;i--){
           linesPrinted++;
           if (linesPrinted > N) break;
           
           System.out.println(lines[i]);
           
          }  
        
    }
    public static String[] sortObjects (Object[] obj){
        
        return null;
    }
}